package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckGroup;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

//检查组mapper服务
public interface CheckGroupDao {

    //    添加检查组数据
    public void add(CheckGroup checkGroup);

    //    添加关联关系
    public void setcheckgroupandcheckitem(Map map);

    //分页管理
    Page<CheckGroup> selectByCondition(String queryString);

    //回写数据
    @Select("select * from t_checkgroup where id=#{id}")
    CheckGroup copyback(Integer id);

    //回写数据检查项信息
    @Select(" SELECT checkitem_id FROM t_checkgroup_checkitem WHERE checkgroup_id=#{id}")
    List<Integer> copybackids(Integer id);

    //    修改检查组
    void edit(CheckGroup checkGroup);

    //删除关联关系
    void deleteAssociation(Integer id);

    //    删除检查组
    @Update("delete from t_checkgroup where id = #{id}")
    void del(Integer id);

    //查询检查组信息
    @Select("select * from t_checkgroup")
    List<CheckGroup> findall();

  //根据套餐id查询检查组数据
  @Select("SELECT  * FROM t_checkgroup WHERE id IN(SELECT checkgroup_id FROM t_setmeal_checkgroup WHERE setmeal_id=#{setmeal_id})")
  @Results({
          @Result(id=true,property = "id",column = "id"),
          @Result(property = "name",column = "name"),
          @Result( column="code",property="code"),
          @Result(column="helpCode" ,property="helpCode"),
          @Result(column="sex", property="sex"),
          @Result(column="age", property="age"),
          @Result(column="price", property="price"),
          @Result(column="remark" ,property="remark"),
          @Result(column="attention", property="attention") ,
          @Result(property = "checkItems",column = "id",
                  javaType = List.class,
                  many = @Many(select = "com.itheima.dao.CheckItemDao.findcheckItemId"))
  })
  public List<CheckGroup>  findCheckGroupId(int setmeal_id);






}
